package com.sto.stoapp.activity.scanner;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.SoleAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.entity.FunctionEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

public class StoScanCarOperatActivity extends StoHomeActivity {
    // 按键映射
    private static final int[] MAPP_TO_KEY = { R.string.loadcar_send_piece,
            R.string.send_car_piece_scan, R.string.to_car_piece_scan };
    private ListView hoursList;

	private SoleAdapter soleAdapter;
	private String boardType = HomeBroadAction.SCANNER_MAN_BROAD;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sto_sales_received_piece);
		Bundle extras = getIntent().getExtras();
		boardType = extras.getString("busiType");
		this.setTitleBottom(R.string.vehicle_operation, boardType);
		initWidget();

	}

	private void initWidget() {
		hoursList = (ListView) findViewById(R.id.receivedFunc_list);
		soleAdapter = new SoleAdapter(this, getResourceList());
		hoursList.setAdapter(soleAdapter);
		hoursList.setOnItemClickListener(new StoOnItemClickListener(this) {

			@Override
			public void KcOnItemClickListener(AdapterView<?> parent, View view,
					int position, long id) {
				TextView title = (TextView) view.findViewById(R.id.res_test);
				clickItemEvent(title.getText().toString());

			}
		});
	}

	private void clickItemEvent(String title) {
		// 网点-装车发件
		if (title.equals(getText(R.string.loadcar_send_piece))) {
			Intent intent = new Intent(this,
					StoScanLoadingSendPieceActivity.class);
			intent.putExtra("busiType", boardType);
			// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		// 网点-发车扫描
		else if (title.equals(getText(R.string.send_car_piece_scan))) {
			Intent intent = new Intent(this, StoScanSendCarScanActivity.class);
			intent.putExtra("busiType", boardType);
			// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		// 网点-到车扫描
		else if (title.equals(getText(R.string.to_car_piece_scan))) {
			// if(boardType.equals(HomeBroadAction.SCANNER_MAN_BROAD)){
			Intent intent = new Intent(this, StoScanReachCarScanActivity.class);
			intent.putExtra("busiType", boardType);
			// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			/*
			 * } // 中转到件 else
			 * if(boardType.equals(HomeBroadAction.CENTER_BROAD)){ Intent intent
			 * = new Intent(this,StoCenterToPieceActivity.class);
			 * startActivity(intent); }else{
			 * 
			 * }
			 */
		}

	}

	private List<FunctionEntity> getResourceList() {
		List<String> resList = new ArrayList<String>();
		resList.add(getText(R.string.loadcar_send_piece).toString());
		resList.add(getText(R.string.send_car_piece_scan).toString());
		resList.add(getText(R.string.to_car_piece_scan).toString());

		List<FunctionEntity> functionList = new ArrayList<FunctionEntity>();
		for (String res : resList) {
			FunctionEntity entity = new FunctionEntity();
			entity.setTitle(res);
			functionList.add(entity);
		}
		return functionList;
	}


	

}
